<?php




$ws = new swoole_websocket_server('172.17.0.2',9502);

$ws->set(['reactor_num'=>4,'worker_num'=>4]);
$ws->on('WorkerStart', function ($ws, $worker_id) { 
   	echo 1;
	
   	//print_r($ws);
   	//echo $worker_id;
   	//定时任务 
    // if ($worker_id == 1) { 
	   //  swoole_timer_tick(3000, function ($timer_id) { 
	   //  	echo "tick-2000ms\n";
	   //  });
    // }
   	$ws->defer(function(){
        echo 'ssss';
    });


});


$ws->on('connect',function($ws,$id){
	echo 2;
	//echo $id;
	//状态 
	print_r($ws->stats());
});

//监听WebSocket连接打开事件 (这里会得到很多信息)
$ws->on('open',function($ws,$request){
	echo 3;
	//print_r($request);
	//用户序号  fd

});

$ws->on("message",function($ws,$frame){

	echo 4;	
	//print_r($frame);
	$ws->push($frame->fd, "server:$frame->data");
	$fdinfo = $ws->getClientInfo($frame->fd);
	print_r($fdinfo);
});

$ws->on('close', function ($ws, $fd) {
    echo "client-{$fd} is closed\n";
});

$ws->listen('172.17.0.2',9503,SWOOLE_SOCK_TCP);

$ws->start();